package Demo.controller;

import Demo.model.Student;
import Demo.service.StudentService;
import Demo.utils.StudentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping(path = "/user")
public class UserController {

    @Autowired
    private StudentService studentService;

    /**
     * 模拟异步请求响应
     * @return   @RequestBody   和    @ResponseBody
     */
    @RequestMapping(path = "/testAjax")
    public @ResponseBody Student testAjax(@RequestBody Student student)
    {
        System.out.println("testAjax执行了。。。");
        //客户端发送ajax的请求，传的是json字符串，后端把json字符串封装到user对象中
        System.out.println("body请求体注入student："+student);
        StudentUtils.Config();
        StudentUtils.update(student);
        return student;
    }

    @RequestMapping(path = "/chakan")
    public String chakan(String username)
    {
        Student student = studentService.selectByUsername(username);
        System.out.println("student："+student);
        return "success";
    }


}
